home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPSETUP.ZIP / APPCHILD.C < prev    next >
C/C++ Source or Header  |  1993-05-02  |  9KB  |  280 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <stdio.h>
  6. #include <ctl3d.h>
  7. #include "appsetup.h"
  8.  
  9. #define MAKECHILD(a,b,c,d,e,f,g,h) CreateWindow(a,b,WS_CHILD | WS_VISIBLE | c,d,e,f,g,hWnd,h,hInst,(LPSTR) NULL)
  10. #define MAKEBUTTON(a,b,c,d,e,f)    MAKECHILD("button",a,BS_PUSHBUTTON,b,c,d,e,f)
  11. #define MAKECHECKBOX(a,b,c,d,e,f)  MAKECHILD("button",a,BS_AUTOCHECKBOX,b,c,d,e,f)
  12. #define MAKERADIO(a,b,c,d,e,f)       MAKECHILD("button",a,BS_RADIOBUTTON,b,c,d,e,f)
  13. #define MAKETEXT(a,b,c,d,e,f)       MAKECHILD("static",a,SS_LEFT,b,c,d,e,f)
  14. #define MAKESTATIC(a,b,c,d)       MAKECHILD("static",NULL,SS_BLACKRECT,a,b,c,d,(HMENU)-1)
  15. #define MAKEBORDER(a,b,c,d)       MAKECHILD("static",NULL,SS_WHITERECT,a,b,c,d,(HMENU) -1)
  16. #define MAKEICON(a,b,c,d,e)       MAKECHILD("button",NULL,BS_OWNERDRAW,a,b,c,d,e)
  17. #define MAKEEDIT(a,b,c,d,e,f)       CreateWindow("edit", "  ", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | a,b,c,d,e,hWnd,f,hInst,(LPSTR) NULL)
  18.  
  19. /*--------------------------------------------------------------------------*/
  20. VOID UpdateEditWindows(int iCurrent)
  21.     {
  22.     char IcoString[32];
  23.  
  24.     sprintf(IcoString,"Program %d",iCurrent+1);
  25.     Static_SetText(hwndText[0], IcoString);
  26.     Edit_SetText(hwndEdit[0], AppButton[iCurrent].ProgName);
  27.  
  28.     sprintf(IcoString,"Parameters %d",iCurrent+1);
  29.     Static_SetText(hwndText[1], IcoString);
  30.     Edit_SetText(hwndEdit[1], AppButton[iCurrent].Params);
  31.  
  32.     sprintf(IcoString,"Working Directory %d",iCurrent+1);
  33.     Static_SetText(hwndText[2], IcoString);
  34.     Edit_SetText(hwndEdit[2], AppButton[iCurrent].StartDir);
  35.  
  36.     sprintf(IcoString,"Icon %d",iCurrent+1);
  37.     Static_SetText(hwndText[3], IcoString);
  38.     Edit_SetText(hwndEdit[3], AppButton[iCurrent].IcoName);
  39.     }
  40.  
  41. /*--------------------------------------------------------------------------*/
  42. VOID UpdateRadioButtons(int iCurrentRB)
  43.     {
  44.     int i;
  45.  
  46.     bSave = TRUE;
  47.     AppButton[iCurrent].ShowMode = iCurrentRB;
  48.     for(i=0;i<4;i++)
  49.     {
  50.     if(i != iCurrentRB)
  51.         Button_SetCheck(hwndRadioButton[i], 0);
  52.     else
  53.         Button_SetCheck(hwndRadioButton[i], 1);
  54.     }
  55.     }
  56.  
  57. /*--------------------------------------------------------------------------*/
  58. VOID UpdateCheckBoxes(int iCurrent)
  59.     {
  60.     Button_SetCheck(hwndButtonLook, AppButton[iCurrent].ButtonLook);
  61.     Button_SetCheck(hwndCloseProg, AppButton[iCurrent].Close);
  62.     Button_SetCheck(hwndNoSound, AppButton[iCurrent].NoSound);
  63.     }
  64.  
  65. /*-------------------------------------------------------------------------*/
  66. VOID UpdateScrollIcons(int iCurrentIcon)
  67.     {
  68.     int i;
  69.  
  70.     iPrevBlackIcon = iBlackIcon;
  71.     iBlackIcon = iCurrentIcon;
  72.     iCurrent -= (iPrevBlackIcon-iCurrentIcon);
  73.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  74.     bCurrentIcon[iBlackIcon] = TRUE;
  75.     UpdateEditWindows(iCurrent);
  76.     UpdateRadioButtons(AppButton[iCurrent].ShowMode);
  77.     UpdateNextButtons(iCurrent);
  78.     UpdateCheckBoxes(iCurrent);
  79.     ScrollBar_SetPos(hwndScroll, iCurrent, TRUE);
  80.     for(i=0;i<NUMICONS;i++)
  81.     {
  82.     InvalidateRect(hwndIcon[i], NULL, TRUE);
  83.     UpdateWindow(hwndIcon[i]);
  84.     }
  85.     }
  86.  
  87. /*--------------------------------------------------------------------------*/
  88. VOID UpdateNextButtons(int iCur)
  89. {
  90.     if(AppButton[iCur].IconNumber <= 0)
  91.     Button_Enable(hwndNext[0], FALSE);
  92.     else
  93.     Button_Enable(hwndNext[0], TRUE);
  94.     if(AppButton[iCur].IconNumber >= MaxIconNumber[iCur]-1)
  95.     Button_Enable(hwndNext[1], FALSE);
  96.     else
  97.     Button_Enable(hwndNext[1], TRUE);
  98. }
  99.  
  100. /*--------------------------------------------------------------------------*/
  101. VOID CreateAllChildWindows(HWND hWnd, HINSTANCE hInst)
  102.     {
  103.     int i;
  104.     char *Button[NUMBUTTONS] ={"Save","Exit","Browse","System","Shell","Sound",
  105.               "Help","Insert","Delete","Move Up","Move Down"};
  106.     char *Next[2] = {"<< "," >>"};
  107.     char *RadioButton[4] = {"Normal","Maximized","Minimized","Maximum size"};
  108.  
  109.     // create static frame around Icons+scroll and editwindows
  110.     Ctl3dSubclassCtl(MAKEBORDER(0, 0, 512, 359));
  111.     Ctl3dSubclassCtl(MAKESTATIC(9, 9, 388, 342));
  112.  
  113.     // create static frame around buttons
  114.     Ctl3dSubclassCtl(MAKESTATIC(406, 9, 98, 342));
  115.  
  116.     // create static frame around checkboxes and radiobuttons
  117.     Ctl3dSubclassCtl(MAKESTATIC(110, 260, 280, 86));
  118.  
  119.     // create windows for the icon buttons
  120.     for(i=0;i<NUMICONS;i++)
  121.     hwndIcon[i] = MAKEICON(10, 10+68*i, 70, 68, IDC_ICONS+i);
  122.  
  123.     // create windows for the push buttons
  124.     for(i=0;i<7;i++)
  125.     hwndButton[i] = MAKEBUTTON(Button[i], 410, 14+i*26, 90, 24,
  126.                    IDC_BUTTONS+i);
  127.  
  128.     for(i=7;i<NUMBUTTONS;i++)
  129.     hwndButton[i] = MAKEBUTTON(Button[i], 410, 28+i*26, 90, 24,
  130.                   IDC_BUTTONS+i);
  131.  
  132.     // create windows for the next push buttons beneath "icon"editwindow
  133.     for(i=0;i<2;i++)
  134.     hwndNext[i] = MAKEBUTTON(Next[i], 110+i*40, 60+(NUMEDITS-1)*58,
  135.                  40, 18, IDC_NEXT+i);
  136.  
  137.     // create windows for buttonlook option checkbox
  138.     hwndButtonLook = MAKECHECKBOX("Buttonlook", 260, 264, 120, 20,
  139.                   IDC_BUTTONLOOK);
  140.     Ctl3dSubclassCtl(hwndButtonLook);
  141.  
  142.     // create windows for no sound option checkbox
  143.     hwndNoSound = MAKECHECKBOX("No Sound", 260, 304, 120, 20,
  144.                   IDC_NOSOUND);
  145.     Ctl3dSubclassCtl(hwndNoSound);
  146.  
  147.     // create windows for close option checkbox
  148.     hwndCloseProg = MAKECHECKBOX("Close Program", 260, 284, 120, 20,
  149.                   IDC_CLOSEPROG);
  150.     Ctl3dSubclassCtl(hwndCloseProg);
  151.  
  152.     // create windows for the showmode radiobuttons
  153.     for(i=0;i<4;i++)
  154.     {
  155.     hwndRadioButton[i] = MAKERADIO(RadioButton[i], 115, 264+i*20, 130, 18,
  156.                   IDC_RADIOS+i);
  157.     Ctl3dSubclassCtl(hwndRadioButton[i]);
  158.     }
  159.  
  160.     // create edit textwindows
  161.     for(i=0;i<NUMEDITS;i++)
  162.     {
  163.     if(i != 1)
  164.         hwndEdit[i] = MAKEEDIT(ES_LOWERCASE, 110, 32+i*58, 280, 28,
  165.                    IDC_EDITS+i);
  166.     if(i == 1)
  167.         hwndEdit[i] = MAKEEDIT(0, 110, 32+i*58, 280, 28, IDC_EDITS+i);
  168.  
  169.     Ctl3dSubclassCtl(hwndEdit[i]);
  170.     Edit_LimitText(hwndEdit[i], MAXFILECHARS-1);
  171.     lpfnOldEdit[i] = (FARPROC) GetWindowLong(hwndEdit[i], GWL_WNDPROC);
  172.     SetWindowLong(hwndEdit[i], GWL_WNDPROC,
  173.           (LONG) MakeProcInstance( (FARPROC) EditProc,
  174.           (HINSTANCE) GetWindowWord(hWnd, GWW_HINSTANCE)));
  175.  
  176.     // create static text windows
  177.     hwndText[i] = MAKETEXT("   ", 110, 11+i*58, 140, 20, IDC_TEXTS+i);
  178.     }
  179.  
  180.     // create scrollbar next to the iconbuttons
  181.     hwndScroll = MAKECHILD("scrollbar", NULL, SBS_VERT, 80, 10, 20, 340,
  182.                IDC_SCROLL);
  183.     }
  184.  
  185. /*--------------------------------------------------------------------------*/
  186. VOID Insert(VOID)
  187.     {
  188.     int i;
  189.     for(i=MAXAPPS-1;i>iCurrent;i--)
  190.     {
  191.     AppButton[i] = AppButton[i-1];
  192.     hIcon[i] = hIcon[i-1];
  193.     }
  194.     AppButton[iCurrent] = AppButtonDefault;
  195.     hIcon[iCurrent] = NULL;
  196.     UpdateScrollIcons(iBlackIcon);
  197.     bSave = TRUE;
  198.     }
  199.  
  200. /*-------------------------------------------------------------------------*/
  201. VOID Delete(VOID)
  202.     {
  203.     int i;
  204.  
  205.     for(i=iCurrent;i<MAXAPPS-1;i++)
  206.     {
  207.     AppButton[i] = AppButton[i+1];
  208.     hIcon[i] = hIcon[i+1];
  209.     }
  210.     AppButton[MAXAPPS-1] = AppButtonDefault;
  211.     hIcon[MAXAPPS-1] = NULL;
  212.     UpdateScrollIcons(iBlackIcon);
  213.     bSave = TRUE;
  214.     }
  215.  
  216. /*--------------------------------------------------------------------------*/
  217. VOID MoveUp(VOID)
  218.     {
  219.     if(iCurrent > 0)
  220.     {
  221.     AppButtonTemp = AppButton[iCurrent-1];
  222.     AppButton[iCurrent-1] = AppButton[iCurrent];
  223.     AppButton[iCurrent] = AppButtonTemp;
  224.     hIconTemp = hIcon[iCurrent-1];
  225.     hIcon[iCurrent-1] = hIcon[iCurrent];
  226.     hIcon[iCurrent] = hIconTemp;
  227.     bSave = TRUE;
  228.     iCurrent--;
  229.     iBlackIcon--;
  230.     iBlackIcon = max(0, min(iBlackIcon, NUMICONS-1));
  231.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  232.     bCurrentIcon[iBlackIcon+1] = FALSE;
  233.     UpdateScrollIcons(iBlackIcon);
  234.     }
  235.     }
  236.  
  237. /*--------------------------------------------------------------------------*/
  238. VOID MoveDown(VOID)
  239.     {
  240.     if(iCurrent < MAXAPPS-1)
  241.     {
  242.     AppButtonTemp = AppButton[iCurrent];
  243.     AppButton[iCurrent] = AppButton[iCurrent+1];
  244.     AppButton[iCurrent+1] = AppButtonTemp;
  245.     hIconTemp = hIcon[iCurrent];
  246.     hIcon[iCurrent] = hIcon[iCurrent+1];
  247.     hIcon[iCurrent+1] = hIconTemp;
  248.     bSave = TRUE;
  249.     iCurrent++;
  250.     iBlackIcon++;
  251.     iBlackIcon = max(0, min(iBlackIcon, NUMICONS-1));
  252.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  253.     bCurrentIcon[iBlackIcon-1] = FALSE;
  254.     UpdateScrollIcons(iBlackIcon);
  255.     }
  256.     }
  257.  
  258. /*--------------------------------------------------------------------------*/
  259. VOID Next(int i)
  260.     {
  261.     bSave = TRUE;
  262.     if(i == DOWN)
  263.     {
  264.     AppButton[iCurrent].IconNumber--;
  265.     AppButton[iCurrent].IconNumber = max(0, AppButton[iCurrent].IconNumber);
  266.     }
  267.     if(i == UP)
  268.     {
  269.     AppButton[iCurrent].IconNumber++;
  270.     AppButton[iCurrent].IconNumber = min(MaxIconNumber[iCurrent]-1, AppButton[iCurrent].IconNumber);
  271.     }
  272.     DestroyIcon(hIcon[iCurrent]);
  273.     hIcon[iCurrent] = ExtractIcon(hInst, AppButton[iCurrent].IcoName, AppButton[iCurrent].IconNumber);
  274.     if(hIcon[iCurrent] == (HICON) 1)
  275.     hIcon[iCurrent] = NULL;
  276.     InvalidateRect(hwndIcon[iBlackIcon], NULL, FALSE);
  277.     UpdateWindow(hwndIcon[iBlackIcon]);
  278.     UpdateNextButtons(iCurrent);
  279.     }
  280.